
const { readJsonFile, getRequest } = require('./common')
/**
 * 获取微信cli参数
 * @param {string} actualProjectPath 小程序项目存放目录 
 * @param {object} giteePushInfo gitee WebHook回调信息
 */
module.exports = (actualProjectPath, giteePushInfo, otherData) => {
  // 获取小程序项目基础信息
  const wxAppletInfo = readJsonFile(`${actualProjectPath}/project.config.json`)

  // 获取commit中?后的数据
  const commitData = getRequest(giteePushInfo.head_commit.message)

  // 获取分支
  let strArr = giteePushInfo.ref.split('/')
  let branch = strArr[strArr.length - 1]

  return {
    name: wxAppletInfo.projectname,
    projectPath: actualProjectPath,
    packageJsonPath: actualProjectPath,
    appid: wxAppletInfo.appid,
    user: giteePushInfo.head_commit.author.username,
    desc: giteePushInfo.head_commit.message,
    privateKeyPath: `${actualProjectPath}/static/private.key`,
    version: commitData.version || '1.0.0',
    branch: branch,
    ...otherData
  }
}